package Offer来了.基础.反射;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

public class CreateObjectTest {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
        Class<?> clazz = Class.forName("Offer来了.基础.反射.User");
        System.out.println("getConstructors:");
        Arrays.stream(clazz.getConstructors()).forEach(System.out::println);
        System.out.println("getDeclaredFields:");
        Arrays.stream(clazz.getConstructors()).forEach(System.out::println);
        System.out.println("getDeclaredMethods:");
        Arrays.stream(clazz.getDeclaredMethods()).forEach(System.out::println);
        //测试方法调用
        Method method = clazz.getMethod("myDefine");
        method.invoke(clazz.newInstance());

    }
}
